<?php

namespace App\Models;

class Fang extends Base
{

    public function setFangConfigAttribute($value)
    {
        $this->attributes['fang_config'] = implode(',',$value);
    }

    public function setFangPicAttribute($value)
    {
        $this->attributes['fang_pic'] = empty($value) ? '' : $value;
    }


    public function getFangCount(){
        $total = self::count();
        $nototal = self::where('fang_status',0)->count();
        $cztotal = $total - $nototal;
        return [
            'total' => $total,
            'nototal' => $nototal,
            'cztotal' => $cztotal,
        ];
    }


    public function owner()
    {
        return $this->belongsTo(FangOwner::class,'fang_owner','id');
    }


    public function getFangAll()
    {
        $data = self::all();
        $result = $this->treeLevel($data);
        return $result;
    }
}
